var Login = function() {

	var handleLogin = function() {
		$('.login-form').validate({
			errorElement : 'span',
			errorClass : 'help-block',
			focusInvalid : false,
			rules : {
				username : {
					required : true
				},
				password : {
					required : true
				},
				remember : {
					required : false
				}
			},

			messages : {
				username : {
					required : "用户名不能为空"
				},
				password : {
					required : "密码不能为空"
				}
			},

			invalidHandler : function(event, validator) {
				$('.alert-danger', $('.login-form')).show();
			},

			highlight : function(element) {
				$(element).closest('.form-group').addClass('has-error');
			},

			success : function(label) {
				label.closest('.form-group').removeClass('has-error');
				label.remove();
			},

			errorPlacement : function(error, element) {
				error.insertAfter(element.closest('.input-icon'));
			},

			submitHandler : function(form) {
				form.submit();
			}
		});

		$('.login-form input').keypress(function(e) {
			if (e.which == 13) {
				if ($('.login-form').validate().form()) {
					$('.login-form').submit();
				}
				return false;
			}
		});
	}
	return {
		init : function() {
			handleLogin();
			$.backstretch([ 
			        "static/assets/admin/pages/media/bg/1.jpg",
					"static/assets/admin/pages/media/bg/2.jpg",
					"static/assets/admin/pages/media/bg/3.jpg",
					"static/assets/admin/pages/media/bg/4.jpg" 
			], {
				fade : 1000,
				duration : 8000
			});
		}
	};
}();